package com.ymttest.database.sqlwapper;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.ymatou.iapi.trading.operate.parameter.OrderInfoPo;
import com.ymatou.iapi.trading.operate.parameter.po.OrderIdCardCostInfoPo;
import com.ymatou.iapi.trading.operate.parameter.po.OrderInfoSubPo;
import com.ymatou.iapi.trading.operate.parameter.po.TradingReqPo;
import com.ymatou.iapi.trading.operate.parameter.req.BizVo;
import com.ymatou.iapi.trading.operate.parameter.req.OrderLogisticsInfoPo;
import com.ymatou.iapi.trading.operate.parameter.resp.OrderGroupExtPo;
import com.ymatou.iapi.trading.sellerquery.parameter.vo.FlowsDetail;
import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.Inventory;
import com.ymttest.utils.EnvSetup;

/************************************************************************************
 * @File name :DefaultWapper.java
 * @Author : zhouyi
 * @Date : 2015年6月1日
 * @Copyright : 洋码头
 ************************************************************************************/
@SuppressWarnings({ "unchecked", "rawtypes", "unused" })
public class DefaultWapper {
	SqlManager manage;

	public DefaultWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}

	/**
	 * @param cid
	 *            产品CatalogId
	 * @return See YmtProductsInActivityWapper#selectNewActiveProductInfo
	 * @see DefaultWapper#selectNewActiveProductInfo
	 * @throws InterruptedException
	 */
	public List<Map> selectProductInActivityInfoByCatalogId(Map m)
			throws InterruptedException {

		List<Map> pia = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsInActivityMapper.selectProductInActivityInfoByCatalogId",
						m);
		// manage.close();
		return pia;
	}

	public List<Map> selectOrderByOderId(long OrderId) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderByOrderId",
						m);
		return result;
	}

	public List<Map> selectOrderSummaryByOrderId(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderSummaryByOrderId",
						m);
		return result;
	}

	public List<Map> selectCreditDetailByOrderId(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectCreditDetailByOrderId",
						m);
		return result;
	}

	public List<Map> selectOrderByMainOderId(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderByMainOderId",
						m);
		return result;
	}

	public Map selectOrderByOderId2(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderByOrderId",
						m);
		return result.get(0);
	}

	public List<Map> selectOrderBySeller(Map m) {
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderBySeller",
						m);
		return result;
	}

	public List<Map> selectOrderExtByOderId(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderExtByOrderId",
						m);
		return result;
	}

	public List<Map> selectOrderPay(long OrderId) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		List<Map> result = manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectOrderPay", m);
		return result;
	}

	public List<Map> selectOrderStateByOderId(long OrderId) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderStateByOrderId",
						m);
		return result;
	}

	public List<Map> selectOrderReasonByOrderIdAndUserId(long OrderId,
			int UserId) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		m.put("UserId", UserId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderReasonByOrderIdAndUserId",
						m);
		return result;
	}

	public List<Map> selectOrderInfoByOderId(long OrderId) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderInfoByOrderId",
						m);
		return result;
	}

	public List<Map> selectOrderInfoExtByOderId(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderInfoExtByOrderId",
						m);
		return result;
		// manage.close();
	}

	/**
	 * 查询本土退货图片url
	 * 
	 * @param OrderId
	 * @return 图片urlList
	 */
	public List<String> selectLocalReturnInfoImgUrlByOrderid(long orderId) {
		List<String> imgUrlList = new ArrayList<String>();
		Map m = new HashMap();
		m.put("OrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectLocalReturnInfoByOrderid",
						m);
		if (result.size() > 0) {
			for (Map tmp : result) {
				imgUrlList.add((String) tmp.get("ImgUrl"));
			}
		}
		return imgUrlList;
	}

	public void updateOrderAutoCancelOrderHoursByOrderId(double Time,
			long OrderId) {
		Map m = new HashMap();
		m.put("Time", Time);
		m.put("OrderId", OrderId);
		manage.update(
				"com.ymttest.database.mapping.DefaultMapper.updateOrderAutoCancelOrderHoursByOrderId",
				m);
		manage.commit();
	}

	public void updateOrderAcceptTimeByOrderId(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		manage.update(
				"com.ymttest.database.mapping.DefaultMapper.updateOrderAcceptTimeByOrderId",
				m);
		manage.commit();
	}

	public void updateOrderDispathTimeByOrderId(long OrderId) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		manage.update(
				"com.ymttest.database.mapping.DefaultMapper.updateOrderDispathTimeByOrderId",
				m);
		manage.commit();
	}

	public void updateOrderPaidTimeByOrderId(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		manage.update(
				"com.ymttest.database.mapping.DefaultMapper.updateOrderPaidTimeByOrderId",
				m);
		manage.commit();
	}

	public void updateOrderConfirmedTimeByOrderId(long OrderId) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		manage.update(
				"com.ymttest.database.mapping.DefaultMapper.updateOrderConfirmedTimeByOrderId",
				m);
		manage.commit();
	}

	/**
	 * 更新Ymt_Order_Frozen 冻结时间为当前时间20天前，使其能自动确认收货
	 * 
	 * @param OrderId
	 * @return
	 */
	public void updateOrderFrozenByOrderId(long OrderId) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		manage.update(
				"com.ymttest.database.mapping.DefaultMapper.updateOrderFrozenByOrderId",
				m);
		manage.commit();
	}

	/**
	 * 查询交易状态
	 * 
	 * @param OrderId
	 * @return
	 */
	public int getTradingStatus(long OrderId) {
		int TradingStatus = 0;
		List<Map> list = new DefaultWapper().selectOrderByOderId(OrderId);
		for (Map s : list) {
			// Logger.debug(s.toString());
			TradingStatus = (Integer) s.get("iTradingStatus");
		}
		return TradingStatus;
	}

	/**
	 * 查询支付金额
	 * 
	 * @param OrderId
	 * @return
	 */
	public BigDecimal getPaidAmountOfCash(long orderId) {
		BigDecimal Cash = null;
		List<Map> list = new DefaultWapper().selectOrderStateByOderId(orderId);
		for (Map s : list) {
			// Logger.debug(s.toString());
			Cash = (BigDecimal) s.get("fPaidAmountOfCash");
		}
		return Cash;
	}

	/**
	 * 查询补款金额
	 * 
	 * @param OrderId
	 * @return
	 */
	public BigDecimal getPostPaidAmountOfCash(long orderId) {
		BigDecimal Cash = null;
		List<Map> list = new DefaultWapper().selectOrderStateByOderId(orderId);
		for (Map s : list) {
			// Logger.debug(s.toString());
			Cash = (BigDecimal) s.get("fPostPaidAmountOfCash");
		}
		return Cash;
	}

	public List<Map> selectOrderTradingStatusByOrderIdAndTradingStatus(
			long OrderId, int TradingStatus) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		m.put("TradingStatus", TradingStatus);
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderTradingStatusByOrderIdAndTradingStatus",
						m);
		return list;
	}

	public List<Map> selectOrderPostPayByOrderId(long OrderId) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderPostPayByOrderId",
						m);
		return list;
	}

	public List<Map> selectOrderFrozenByOrderId(long OrderId) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderFrozenByOrderId",
						m);
		return list;
	}

	public List<Map> selectOrderFrozenDetailByOrderId(long OrderId) {
		Map m = new HashMap();
		m.put("OrderId", OrderId);
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderFrozenDetailByOrderId",
						m);
		return list;
	}

	public List<Map> selectOrderNoteByOrderId(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderNoteByOrderId",
						m);
		return result;
	}

	public List<Map> selectOrderNoteHistoryByOrderId(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderNoteHistoryByOrderId",
						m);
		return result;
	}

	public Map selectOrderAddressHistoryByOrderId(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderAddressHistoryByOrderId",
						m);
		return result.get(0);
	}

	public List<Map> selectTradingitemByTradingId(int TradingId) {
		Map m = new HashMap();
		m.put("TradingId", TradingId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectTradingitemByTradingId",
						m);
		return result;
	}

	/**
	 * 根据交易Id查询交易信息
	 * 
	 * @param TradingId
	 * @return
	 */
	public List<Map> selectTradinginfoByTradingId(int TradingId) {
		Map m = new HashMap();
		m.put("TradingId", TradingId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectTradinginfoByTradingId",
						m);
		return result;
	}

	/**
	 * 根据订单号查询交易通知
	 * 
	 * @param OrderId
	 * @return
	 */
	public List<Map> selectTradingNotifaction(HashMap m) {
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectTradingNotifaction",
						m);
		return result;
	}

	/**
	 * 根据订单号查询交易通知
	 * 
	 * @param OrderId
	 * @return
	 */
	public List<Map> selectTradingNotifactionByOrderId(long orderId) {
		Map m = new HashMap();
		m.put("iOrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectTradingNotifactionByOrderId",
						m);
		return result;
	}

	/**
	 * 根据订单号查询交易状态表
	 * 
	 * @param OrderId
	 * @return
	 */
	public List<Map> selectTradingStatusByOrderId(long orderId) {
		Map m = new HashMap();
		m.put("iOrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectTradingStatusByOrderId",
						orderId);
		return result;
	}

	/**
	 * 获取补款交易ID
	 * 
	 * @param OrderId
	 * @return
	 */
	public String getPostPayTradingId(long orderId) {
		String PostPayTradingId = null;
		List<Map> list = new DefaultWapper()
				.selectOrderPostPayByOrderId(orderId);
		for (Map s : list) {
			// Logger.debug(s.toString());
			PostPayTradingId = (String) s.get("sId");
		}
		return PostPayTradingId;
	}

	/**
	 * 获取补款交易Action
	 * 
	 * @param OrderId
	 * @return
	 */
	public int getAction(long orderId) {
		Integer Action = 0;
		List<Map> list = new DefaultWapper()
				.selectOrderPostPayByOrderId(orderId);
		for (Map s : list) {
			// Logger.debug(s.toString());
			Action = (Integer) s.get("iAction");
		}
		return Action;
	}

	/**
	 * 查询扣款记录
	 * 
	 * @param UserId
	 * @param OrderId
	 * @return
	 */
	public List<Map> selectAccountRunningTallyByUserIdAndOrderId(int UserId,
			long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId + "");
		m.put("UserId", UserId);
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectAccountRunningTallyByUserIdAndOrderId",
						m);
		return list;
	}

	/**
	 * 查询交易状态表
	 * 
	 * @param m
	 * @return
	 */
	public List<Map> selectTradingStatus(HashMap m) {
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectTradingStatus",
						m);
		return result;
	}

	/**
	 * 查询订单表
	 * 
	 * @param m
	 * @return
	 */
	public List<Map> selectOrder(HashMap m) {
		List<Map> result = manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectOrder", m);
		return result;
	}

	/**
	 * 查询订单表扩展表
	 * 
	 * @param m
	 * @return
	 */
	public List<Map> selectOrderExtByBuyerIdAndName(HashMap m) {
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderExtByBuyerIdAndName",
						m);
		return result;
	}

	/**
	 * 查询物流信息表
	 * 
	 * @param m
	 * @return
	 */
	public List<Map> selectOrderSummary(HashMap m) {
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderSummary",
						m);
		return result;
	}

	/**
	 * 查询物流信息表
	 * 
	 * @param orderId
	 * @return
	 */
	public List<Map> selectOrderSummary(long orderId) {
		Map m = new HashMap();
		m.put("OrderId", orderId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderSummary",
						m);
		return result;
	}

	/**
	 * 查询账户信息
	 * 
	 * @param m
	 * @return
	 */
	public List<Map> selectAccountInfo(HashMap m) {
		List<Map> result = manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectAccountInfo",
				m);
		return result;
	}

	/**
	 * 查询退款记录表
	 * 
	 * @param m
	 *            （OrderId and FAmount）
	 * @return
	 */
	public List<Map> selectRefundRecord(HashMap m) {
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectRefundRecord",
						m);
		return result;
	}

	/**
	 * 修改指定账户余额
	 * 
	 * @param Amount
	 * @param UserId
	 */
	public void updateAccountInfo(BigDecimal Amount, int UserId) {
		Logger.comment("修改指定账户余额:" + UserId + ":" + Amount);
		HashMap m = new HashMap();
		m.put("Amount", Amount);
		m.put("UserId", UserId);
		int result = manage.update(
				"com.ymttest.database.mapping.DefaultMapper.updateAccountInfo",
				m);
		manage.commit();
	}

	/**
	 * 修改红包账户金额
	 * 
	 * @param Amount
	 * @param UserId
	 */
	public void updateGiftAccountInfo(BigDecimal Amount, int UserId) {
		HashMap m = new HashMap();
		m.put("Amount", Amount);
		m.put("UserId", UserId);
		int result = manage
				.update("com.ymttest.database.mapping.DefaultMapper.updateGiftAccountInfo",
						m);
		manage.commit();
	}

	/**
	 * 修改订单状态
	 * 
	 * @param TradingStatus
	 * @param OrderId
	 */
	public void updateTradingStatus(int TradingStatus, long orderId) {
		HashMap m = new HashMap();
		m.put("TradingStatus", TradingStatus);
		m.put("OrderId", orderId);
		int Result = manage
				.update("com.ymttest.database.mapping.DefaultMapper.updateTradingStatus",
						m);
		manage.commit();
	}

	/**
	 * 修改订单状态
	 * 
	 * @param TradingStatus
	 * @param OrderId
	 */
	public void updateOrderbCanLocalReturn(long orderId) {
		HashMap m = new HashMap();
		m.put("iOrderId", orderId);
		int Result = manage
				.update("com.ymttest.database.mapping.DefaultMapper.updateOrderbCanLocalReturn",
						m);
		manage.commit();
	}

	/**
	 * 查询指定批次指定买家的优惠券
	 * 
	 * @param UserId
	 * @param BatchId
	 * @return
	 */
	public String selectCouponCode(int UserId, int BatchId) {
		Map m = new HashMap();
		m.put("UserId", UserId);
		m.put("BatchId", BatchId);
		List<Map> list = manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectCouponCode",
				m);
		String CouponCode = (String) list.get(0).get("sCouponCode");
		return CouponCode;
	}

	/**
	 * 查询指定订单号结算同步表
	 * 
	 * @param orderId
	 * @return
	 */
	public List<Map> selectYmtSettlementInvoice(long orderId) {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectYmtSettlementInvoice",
						orderId);
		return list;
	}

	/**
	 * 查询已发货未确认收货的订单（贝海发货）
	 * 
	 * @return list
	 * 
	 * */
	public List<Map> selectOrderDispatched(int BusynessType) {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderDispatched",
						BusynessType);
		return list;
	}

	/**
	 * 查询app中好货商品
	 * 
	 * @param keyword
	 * @return
	 */
	public List<Map> selectProductInPc(String keyword) {
		List<Map> list = manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectProductInPc",
				keyword);
		return list;

	}

	/**
	 * 查询所有认证买手
	 * 
	 * @return list
	 * 
	 * */
	public List selectLicenceSeller() {
		List<Inventory> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectLicenceSeller",
						null);
		return list;

	}

	/**
	 * 从PaymentNotify中查询支付流水
	 * 
	 * @param orderId
	 * @return
	 */
	public List<Map> queryInstitutePaymentsByOrderFromPaymentNotify() {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.queryInstitutePaymentsByOrderFromPaymentNotify",
						null);
		return list;

	}

	public List<Map> selectUsers() {
		List<Map> list = manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectUsers", null);
		return list;

	}

	public List<Map> selectLoginIdUpdateHistory() {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectLoginIdUpdateHistory",
						null);
		return list;

	}

	/**
	 * 查询可用InstitutionPaymentId
	 * 
	 * @return
	 */
	public Map queryIPayment30() {
		List<Map> list = manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.queryIPayment30",
				null);
		Map m = (Map) list.get(0);
		return m;

	}

	/**
	 * 从PaymentNotify中查询支付流水
	 * 
	 * @param orderId
	 * @return
	 */
	public List<Map> queryInstitutePaymentsByOrderFromYmtTradingItem() {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.queryInstitutePaymentsByOrderFromYmtTradingItem",
						null);
		return list;

	}

	/**
	 * 从PaymentNotify中查询支付流水
	 * 
	 * @param orderId
	 * @return
	 */
	public List<Map> queryInstitutePaymentsByOrderFromYmtPostPayTradingInfo() {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.queryInstitutePaymentsByOrderFromYmtPostPayTradingInfo",
						null);
		return list;

	}

	/**
	 * 从PaymentNotify中查询支付流水
	 * 
	 * @param orderId
	 * @return
	 */
	public List<Map> queryOrderByPaymentFromPaymentNotify() {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.queryOrderByPaymentFromPaymentNotify",
						null);
		return list;

	}

	/**
	 * 从PaymentNotify中查询支付流水
	 * 
	 * @param orderId
	 * @return
	 */
	public List<Map> queryOrderByPaymentFromYmtTradingItem() {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.queryOrderByPaymentFromYmtTradingItem",
						null);
		return list;

	}

	/**
	 * 从PaymentNotify中查询支付流水
	 * 
	 * @param orderId
	 * @return
	 */
	public List<Map> queryOrderByPaymentFromYmtPostPayTradingInfo() {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.queryOrderByPaymentFromYmtPostPayTradingInfo",
						null);
		return list;

	}

	/**
	 * 查询补款第三方支付交易号
	 * 
	 * @param orderId
	 * @return
	 */
	public List<Map> queryPostPayTradingInfoAndPayment(long orderId) {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.queryPostPayTradingInfoAndPayment",
						orderId);
		return list;

	}

	/**
	 * 查询退单
	 * 
	 * @param orderId
	 * @return
	 */
	public List<Map> queryRefundrequestByApproveStatus(int approveStatus) {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.queryRefundrequestByApproveStatus",
						approveStatus);
		return list;

	}

	/**
	 * 查询退单
	 * 
	 * @param orderId
	 * @return
	 */
	public List<Map> queryRefundrequestByApproveStatusAndRefundStatus(
			int approveStatus, int refundStatus) {
		Map m = new HashMap();
		m.put("approveStatus", approveStatus);
		m.put("refundStatus", refundStatus);
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.queryRefundrequestByApproveStatusAndRefundStatus",
						m);
		return list;

	}

	/**
	 * 查询买手国家与可以发的物流类型mapping表
	 * 
	 * @param userId
	 * @return
	 */
	public List<Map> selectCatalogStatusByCountryId(int userId) {
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectCatalogStatusByCountryId",
						userId);
		return list;
	}

	/**
	 * 获取需要清关订单
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> getSyncOrderLogisticStatusRequestList(int num)
			throws InterruptedException {
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.getSyncOrderLogisticStatusRequestList",
						num);
	}

	/**
	 * 获取订单状态
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public int getFrozenStatus(long orderId) throws InterruptedException {
		return Integer
				.parseInt(manage
						.getSelectResults(
								"com.ymttest.database.mapping.DefaultMapper.getFrozenStatus",
								orderId).get(0).toString());
	}

	/**
	 * 
	 * @param queryField
	 *            查询字段
	 * @param queryCondition
	 *            查询条件
	 * @return
	 */
	public List<Map> getFrozenDetail(String queryField, String queryCondition) {
		Map map = new HashMap();
		map.put("queryField", queryField);
		map.put("queryCondition", queryCondition);
		return manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.getFrozenDetail",
				map);
	}

	/**
	 * 获取订单状态
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public Map getFrozenStatusInOrderFrozen(long orderId)
			throws InterruptedException {
		return (Map) manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.getFrozenStatusInOrderFrozen",
						orderId).get(0);

	}

	/**
	 * 商品名关键字优化 - 查询库mongo缓存在mssql中的md5标记
	 * 
	 * @param sellerid
	 *            商家id
	 * @param pname2md5
	 *            商品名md5码
	 * @return Trd_SellerProductNames
	 * @throws InterruptedException
	 */
	public Map selectTrdSellerProductNames(int sellerid, String pname2md5)
			throws InterruptedException {
		Map m = new HashMap();
		m.put("sellerId", sellerid);
		m.put("md5", pname2md5);
		return (Map) manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectTrdSellerProductNames",
						m).get(0);

	}

	/**
	 * 获取最后一个绑定的微信用户信息
	 * 
	 * @return {sSex=女, sRegSource=Wap, sToken=
	 *         OezXcEiiBSKSxW0eoylIeKIpvo3OcRKtukvAChoKMykZVEZFS2hVukKo58bHUpq6_0sLL95JCOxLGszoogVC0qfR7aA_k8H
	 *         -NuV5OGrdotjhIgtUSozdbJbJ39jEPDzb3elFrbWXMj5BoWcrn1Sjew,
	 *         sCity=苏州, sOpenId=oR5W7jpIo4tTnhTRHYB3AXBufLiA,
	 *         dAddTime=2016-04-09 11:24:24.73, sNickname=, sCountry=中国,
	 *         sHeadimgurl=http://wx.qlogo.cn/mmopen/
	 *         TOEj6AkibIpmtMjRM63g1YM3zsSuFyWBmF4mfSgFMmu3qpDoeIW5ftTqggysBQPjI95xVqfrgKCIvfbsaTRIQ1Q
	 *         /0, iYmtUserId=20226730, sUnionId=oA7HCt-ikAk6usPsP4GiZexhoyjc,
	 *         sProvince=江苏}
	 * @throws InterruptedException
	 */
	public Map selectLastWeixinUser() throws InterruptedException {
		return (Map) manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectLastWeixinUser",
						null).get(0);

	}

	/**
	 * 根据卖家，用户查询是否有订单数据
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectOrderByUserAndSeller(int sellerId, int userId)
			throws InterruptedException {
		Map m = new HashMap();
		m.put("sellerId", sellerId);
		m.put("userId", userId);
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderByUserAndSeller",
						m);

	}

	/**
	 * 查询最近200条已付款订单数据
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectLastestPaidOrders() throws InterruptedException {
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectLastestPaidOrders",
						null);

	}

	/**
	 * 根据orderId查询卖家营销活动
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectSellerPromotion(long orderId)
			throws InterruptedException {
		Map m = new HashMap();
		m.put("orderId", orderId);
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectSellerPromotion",
						m);

	}

	/**
	 * 根据订单号，删除订单补款记录
	 * 
	 * @param TradingStatus
	 * @param OrderId
	 */
	public int deleteOrderPostPayByOrderId(long OrderId) {
		HashMap m = new HashMap();
		m.put("orderId", OrderId);
		int result = manage
				.delete("com.ymttest.database.mapping.DefaultMapper.deleteOrderPostPayByOrderId",
						m);
		manage.commit();
		return result;
	}

	/**
	 * 根据orderId查询订单余额退款表
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectAccountRefundInstruction(long orderId)
			throws InterruptedException {
		Map m = new HashMap();
		m.put("orderId", orderId);
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectAccountRefundInstruction",
						m);

	}

	/**
	 * 根据orderId查询第三方退款表
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectThirdPartyRefundInstruction(long orderId)
			throws InterruptedException {
		Map m = new HashMap();
		m.put("orderId", orderId);
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectThirdPartyRefundInstruction",
						m);

	}

	/**
	 * 根据orderId查询第三方退款申请表
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectRefundRequest(String orderId)
			throws InterruptedException {
		Map<String, String> m = new HashMap();
		m.put("orderId", orderId);
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectRefundRequest",
						m);

	}

	/**
	 * 根据orderId查询补款生成的第三方交易号
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectPostPayTradingInfo(long orderId)
			throws InterruptedException {
		Map m = new HashMap();
		m.put("orderId", orderId);
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectPostPayTradingInfo",
						m);

	}

	public List<Map> selectUsers2(int userId) throws InterruptedException {
		Map m = new HashMap();
		m.put("userId", userId);
		return manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectUsers2", m);

	}

	public List<Map> MobilePhoneAccount(int userId) throws InterruptedException {
		Map m = new HashMap();
		m.put("userId", userId);
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.MobilePhoneAccount",
						m);

	}

	/**
	 * Ymt_ActivityProductSubsidy 查询补贴商品活动信息表
	 * 
	 * @return 从10个查询结果里，随机返回一条
	 * @throws InterruptedException
	 */
	public HashMap selectActivityProductSubsidy() throws InterruptedException {
		List<Map> activityProductSubsidyList = new ArrayList<Map>();
		activityProductSubsidyList = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectActivityProductSubsidy",
						null);

		return (HashMap) activityProductSubsidyList.get(new Random()
				.nextInt(activityProductSubsidyList.size()));
	}

	/**
	 * Ymt_PaymentInstruction 查询交易支付指令表
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public HashMap selectPaymentInstructionByNewtradingId(String string)
			throws InterruptedException {
		HashMap map = new HashMap();
		Map m = new HashMap();
		m.put("newTradingId", string);
		List<Map> paymentInstructionL = new ArrayList<Map>();
		paymentInstructionL = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectPaymentInstructionByNewtradingId",
						m);
		if (paymentInstructionL.size() > 0) {
			map = (HashMap) paymentInstructionL.get(0);
		}
		return map;
	}

	/**
	 * 根据orderIdYmt_SubsidySettlementInvoice 补贴商品结算表
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectSubsidySettlementInvoiceByOrderId(long orderId)
			throws InterruptedException {
		Map m = new HashMap();
		m.put("orderId", orderId);
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectSubsidySettlementInvoiceByOrderId",
						m);
	}

	/**
	 * 根据OrderInfoId ymt_orderinfo 查询订单信息表
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectOrderInfoByOrderInfoId(String orderInfoId) {
		Map m = new HashMap();
		m.put("orderInfoId", orderInfoId);
		List<Map> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderInfoByOrderInfoId",
						m);
		return result;
	}

	/**
	 * 根据orderid ymt_orderinfo 查询订单信息表
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<OrderInfoPo> selectOrderInfoByOrderId2(int orderId) {

		Map m = new HashMap();
		m.put("orderId", orderId);
		List<OrderInfoPo> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderInfoByOrderId2",
						m);
		return result;
	}

	/**
	 * 
	 * @param queryField
	 *            查询的字段
	 * @param joinCondition
	 *            连表查询
	 * @param queryCondition
	 *            查询条件
	 * @return
	 */
	public List<Map> selectOrderInfo(String queryField, String joinCondition,
			String queryCondition) {
		Map m = new HashMap();
		if (null != queryField && !"".equals(queryField)) {
			m.put("queryField", queryField);
		}
		if (null != joinCondition && !"".equals(joinCondition)) {
			m.put("joinCondition", joinCondition);
		}
		if (null != queryCondition && !"".equals(queryCondition)) {
			m.put("queryCondition", queryCondition);
		}
		return (List<Map>) manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderInfo",
						m);
	}

	public List<Map> selectOrderStatesByOrderIds(String queryField,
			String joinCondition, String queryCondition) {
		Map m = new HashMap();
		if (null != queryField && !"".equals(queryField)) {
			m.put("queryField", queryField);
		}
		if (null != joinCondition && !"".equals(joinCondition)) {
			m.put("joinCondition", joinCondition);
		}
		if (null != queryCondition && !"".equals(queryCondition)) {
			m.put("queryCondition", queryCondition);
		}
		return (List<Map>) manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderStatesByOrderIds",
						m);
	}

	public List<Map> selectOrderSummary2(String queryField,
			String joinCondition, String queryCondition) {
		Map m = new HashMap();
		if (null != queryField && !"".equals(queryField)) {
			m.put("queryField", queryField);
		}
		if (null != joinCondition && !"".equals(joinCondition)) {
			m.put("joinCondition", joinCondition);
		}
		if (null != queryCondition && !"".equals(queryCondition)) {
			m.put("queryCondition", queryCondition);
		}
		return (List<Map>) manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderSummary2",
						m);
	}

	public List<Map> selectOrderPostPay(String queryField,
			String joinCondition, String queryCondition) {
		Map m = new HashMap();
		if (null != queryField && !"".equals(queryField)) {
			m.put("queryField", queryField);
		}
		if (null != joinCondition && !"".equals(joinCondition)) {
			m.put("joinCondition", joinCondition);
		}
		if (null != queryCondition && !"".equals(queryCondition)) {
			m.put("queryCondition", queryCondition);
		}
		return (List<Map>) manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderPostPay",
						m);
	}

	public List<Map> selectOrderFrozen(String queryField, String joinCondition,
			String queryCondition) {
		Map m = new HashMap();
		if (null != queryField && !"".equals(queryField)) {
			m.put("queryField", queryField);
		}
		if (null != joinCondition && !"".equals(joinCondition)) {
			m.put("joinCondition", joinCondition);
		}
		if (null != queryCondition && !"".equals(queryCondition)) {
			m.put("queryCondition", queryCondition);
		}
		return (List<Map>) manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectOrderFrozen",
				m);
	}

	public List<Map> selectOrderToBill(String queryField, String joinCondition,
			String queryCondition) {
		Map m = new HashMap();
		if (null != queryField && !"".equals(queryField)) {
			m.put("queryField", queryField);
		}
		if (null != joinCondition && !"".equals(joinCondition)) {
			m.put("joinCondition", joinCondition);
		}
		if (null != queryCondition && !"".equals(queryCondition)) {
			m.put("queryCondition", queryCondition);
		}
		return (List<Map>) manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectOrderToBill",
				m);
	}

	public List<Map> selectBill(String queryField, String joinCondition,
			String queryCondition) {
		Map m = new HashMap();
		if (null != queryField && !"".equals(queryField)) {
			m.put("queryField", queryField);
		}
		if (null != joinCondition && !"".equals(joinCondition)) {
			m.put("joinCondition", joinCondition);
		}
		if (null != queryCondition && !"".equals(queryCondition)) {
			m.put("queryCondition", queryCondition);
		}
		return (List<Map>) manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectBill", m);
	}

	public List<Map> selectTradingInfo(String queryField, String joinCondition,
			String queryCondition) {
		Map m = new HashMap();
		if (null != queryField && !"".equals(queryField)) {
			m.put("queryField", queryField);
		}
		if (null != joinCondition && !"".equals(joinCondition)) {
			m.put("joinCondition", joinCondition);
		}
		if (null != queryCondition && !"".equals(queryCondition)) {
			m.put("queryCondition", queryCondition);
		}
		return (List<Map>) manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectTradingInfo",
				m);
	}

	public List<Map> selectSettlementInvoice(String queryField,
			String joinCondition, String queryCondition) {
		Map m = new HashMap();
		if (null != queryField && !"".equals(queryField)) {
			m.put("queryField", queryField);
		}
		if (null != joinCondition && !"".equals(joinCondition)) {
			m.put("joinCondition", joinCondition);
		}
		if (null != queryCondition && !"".equals(queryCondition)) {
			m.put("queryCondition", queryCondition);
		}
		return (List<Map>) manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectSettlementInvoice",
						m);
	}

	public List<Map> executeSql(Object sqlCmd) {
		Map m = new HashMap();
		m.put("sqlCmd", sqlCmd.toString());
		return (List<Map>) manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.executeSql", m);
	}

	public void executeUpdateSql(Object sqlCmd) {

		Map m = new HashMap();
		m.put("sqlCmd", sqlCmd.toString());

		manage.update(
				"com.ymttest.database.mapping.DefaultMapper.executeUpdateSql",
				m);

		manage.commit();

	}

	/**
	 * 根据组合条件查询买手下用户信息
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<String> getSellerConsumersList(Map m)
			throws InterruptedException {
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.getSellerConsumersList",
						m);

	}

	/**
	 * 查询 getOrderFlows 接口
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<FlowsDetail> getOrderFlows(Map m) throws InterruptedException {
		return manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.getOrderFlows", m);

	}

	/**
	 * 查询 ymt_orderbiz
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<BizVo> selectYmtOrderbiz(Map m) throws InterruptedException {

		return manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectYmtOrderbiz",
				m);

	}

	/**
	 * 查询 Ymt_OrderLogisticsInfo
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<OrderLogisticsInfoPo> selectOrderLogisticsInfo(int orderId)
			throws InterruptedException {
		Map m = new HashMap();
		m.put("orderId", orderId);
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderLogisticsInfo",
						m);

	}

	/**
	 * Ts_GetOrderGroupInfos 支付之前查询主单信息(防止买家查询服务异常,导致无法下单支付)
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public List<OrderGroupExtPo> getGroupOrderInfoByMainOrderId(
			long mainOrderId, long userId) throws InterruptedException {
		Map m = new HashMap();
		m.put("mainOrderId", mainOrderId);
		m.put("userId", userId);
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.getGroupOrderInfoByMainOrderId",
						m);

	}

	/**
	 * Ts_GetOrderGroupInfos 支付之前查询主单信息(防止买家查询服务异常,导致无法下单支付)
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public TradingReqPo getTradingReq(Map map) throws InterruptedException {

		List<TradingReqPo> results = new ArrayList<TradingReqPo>();

		results = manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.selectTradingreq",
				map);

		return results.get(0);

	}

	/**
	 * 年度消费金额
	 * 
	 * @return
	 * @throws InterruptedException
	 */
	public OrderIdCardCostInfoPo getOrderIdCardCostInfo(Map map)
			throws InterruptedException {

		List<OrderIdCardCostInfoPo> results = new ArrayList<OrderIdCardCostInfoPo>();

		results = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderIdCardCostInfo",
						map);

		return results.get(0);

	}

	/**
	 * 组合商品
	 * 
	 * @return List<OrderInfoSubPo>
	 * @throws InterruptedException
	 */
	public List<OrderInfoSubPo> getOrderInfoSub(long orderId, String catalogId)
			throws InterruptedException {

		Map map = new HashMap();

		map.put("orderId", orderId);

		map.put("catalogId", catalogId);

		List<OrderInfoSubPo> results = new ArrayList<OrderInfoSubPo>();

		results = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectOrderInfoSub",
						map);

		return results;

	}

	/**
	 * 组合商品
	 * 
	 * @return List<OrderInfoSubPo>
	 * @throws InterruptedException
	 */
	public List<Map> getAdOrderInfo(int userId, int sellerId, int orderId,
			List<String> proList) throws InterruptedException {

		Map map = new HashMap();

		map.put("userId", userId);
		map.put("sellerId", sellerId);
		map.put("orderId", orderId);
		map.put("proList", proList);

		return manage.getSelectResults(
				"com.ymttest.database.mapping.DefaultMapper.getAdOrderInfo",
				map);

	}

	/**
	 * 获取wxtoken
	 * 
	 * @param type
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectWXSignatureRecored(int type)
			throws InterruptedException {
		Map m = new HashMap();
		m.put("type", type);
		List<Map> list = manage
				.getSelectResults(
						"com.ymttest.database.mapping.DefaultMapper.selectWXSignatureRecored",
						m);
		manage.commit();
		return list;
	}

	/**
	 * 设置skey
	 * 
	 * @param id
	 * @param skey
	 * @return
	 * @throws InterruptedException
	 */
	public int updateWXSignatureRecored(int id, String skey)
			throws InterruptedException {
		Map m = new HashMap();
		m.put("id", id);
		m.put("skey", skey);
		int i = manage
				.update("com.ymttest.database.mapping.DefaultMapper.updateWXSignatureRecored",
						m);
		manage.commit();
		return i;
	}

	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	public static void main(String args[]) throws InterruptedException {
		DefaultWapper df = new DefaultWapper();

		System.out.println(df.selectOrderAddressHistoryByOrderId(112767231)
				.get("UserTelePhone"));

	}
}
